package com.gitee.beiding.cloud.base.utils;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.RootBeanDefinition;

public class BeanDefinitionUtils {

    public static BeanDefinition createBeanDefinition(Object bean) {
        ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
        constructorArgumentValues.addGenericArgumentValue(bean);
        return new RootBeanDefinition(BeanWrapper.class, constructorArgumentValues, null);
    }

    static class BeanWrapper implements FactoryBean {
        private Object bean;

        public BeanWrapper(Object bean) {
            this.bean = bean;
        }
        @Override
        public Object getObject() throws Exception {
            return bean;
        }
        @Override
        public Class<?> getObjectType() {
            return bean.getClass();
        }
    }

}
